<%--
    Document   : squadsForm
    Created on : Nov 23, 2012, 5:59:23 PM
    Author     : newohybat
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<s:form beanclass="cz.muni.fi.pa165.ddtroops.web.actionbeans.SquadActionBean">
    <fieldset><legend><tiles:getAsString name="legend"/></legend>
        <tiles:importAttribute name="hidden" />
    <s:hidden name="${hidden}"/>
    <s:errors/>
    <div id="form">
        <div class="row">
            <s:label for="b1" name="squad.name"/>
            <s:text id="b1" name="squad.name"/>
            <div class="accordion">
                <s:label for="requiredValue"/>
            </div>
        </div>
            
        <div class="row">
            <s:label for="b2" name="squad.description"/>
            <s:text id="b2" name="squad.description"/>
            <div class="accordion">
                <s:label for="requiredValue"/>
            </div>
        </div>
            
        <div class="row">
            <s:label for="b3" name="squad.task"/>
            <s:text id="b3" name="squad.task"/>
            <div class="accordion">
                <s:label for="requiredValue"/>
            </div>
        </div>
            
        <div class="row">
            <s:label for="b4" name="squad.gold"/>
            <s:text id="b4" name="squad.gold"/>
            <div class="accordion">
                <s:label for="requiredValue"/>
            </div>
        </div>
            
        <div class="row">
            <s:label for="b5" name="squad.members"/>
            <c:forEach items="${actionBean.squad.members}" var="member">
                    <input type="hidden" class="membersToBeChecked" value="${member.id}"/>
                </c:forEach>
                <c:forEach items="${actionBean.heroes}" var="hero">
                    <s:checkbox class="b5" name="squad.members" value="${hero.id}" title="${hero.name}"/>
                    <c:out value = "${hero.name}"/>
                </c:forEach>
            <div class="accordion">
                <s:label for="requiredValue"/>
            </div>
        </div>
            
        <div class="row">
            <s:label for="b6" name="squad.leader"/>
            <input type="hidden" id="leader" value="${actionBean.squad.leader.id}"/>
                <s:select id="b6" name="squad.leader">
                            <s:option value="${actionBean.squad.leader.id}" label="${actionBean.squad.leader.name}"/>
                </s:select>
        </div>
    </div>
    
    <tiles:importAttribute name="action" />
    <div class="cent">
    <s:submit name="${action}"><tiles:getAsString name="button"/></s:submit>
    </div>
    </fieldset>
</s:form>

<script type="text/javascript">
    $(document).ready(function(){
        $('.membersToBeChecked').each(function(key,value){
            $(".b5[value="+value.value+"]").attr("checked",true);
        });
        $("#b6 option").remove();
        $(".b5:input:checked").each(function(key,value){
            $("#b6 ").append("<option value='"+value.value+"'>"+value.title+"</option>");
        });
        $('#leader').each(function(key,value){
           $("#b6 option[value="+value.value+"]").attr("selected",true);
        });

    });
    $(".b5").click(function(e){
        $("#b6 option").remove();
        $(".b5:input:checked").each(function(key,value){
            $("#b6 ").append("<option value='"+value.value+"'>"+value.title+"</option>");
        });
    });

</script>